{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>次卡添加</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <input type="hidden" name="id" value="{$list.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">次卡名称</label>
            <div class="layui-input-4">
                <input type="text" maxlength="200" name="title" value="{$list.title}" lay-verify="required" placeholder="请输入次卡名称"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">次卡价格</label>
            <div class="layui-input-4">
                <input type="number" maxlength="200" name="money" value="{$list.money}" lay-verify="required" placeholder="请输入次卡价格"
                    class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">次卡出售价格</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">logo</label>
            <input type="hidden" lay-verify="logo" name="logo" id="logo2" value="{$list.logo}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="logoBtn2"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list" >
                        <img class="layui-upload-img" id="SLogo2" src="{$list.logo}" >
                        <p id="demoText2"></p>
                    </div>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">次卡次数</label>
            <div class="layui-input-4">
                <input type="number" maxlength="200" name="num" value="{$list.num}" lay-verify="required" placeholder="次卡次数"
                    class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">一张次卡所包含的住店次数</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">有效时间</label>
            <div class="layui-input-4">
                <input type="text" maxlength="200" name="endtime" value="{$list.endtime}" lay-verify="required"
                    placeholder="请输入次卡有效时间（天数）" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">次卡从添加到停止出售使用的天数。</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-4">
                <input type="radio" name="status" value="0" title="正常" {if $list.status==0}checked{/if}>
                <input type="radio" name="status" value="1" title="下架" {if $list.status==1}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">库存</label>
            <div class="layui-input-4">
                <input type="number" maxlength=" 200" name="number" value="{$list.number}" lay-verify="required"
                    placeholder="次卡剩余的数量" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">发放次卡的数量</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">活动领取</label>
            <div class="layui-input-4">
                <input type="radio" name="is_activity" value="0" title="否" {if $list.is_activity==0}checked{/if}>
                <input type="radio" name="is_activity" value="1" title="是" {if $list.is_activity==1}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="submit" lay-submit=""
                    lay-filter="sys">{:lang('submit')}</button>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script>
 
    layui.use(['form', 'layer', 'upload', 'laydate'], function () {
        var form = layui.form, layer = layui.layer, upload = layui.upload, $ = layui.jquery;
        let laydate = layui.laydate;
        form.verify({
            title: function (value) {
                if (value == '') {
                    return '请输入网站名称！';
                }
            },
            title: function (value) {
                if (value == '') {
                    return '请输入次卡标题！';
                }
            },
            money: function (value) {
                if (value == '') {
                    return '请输入后台标题！';
                }
            },
            number: function (value) {
                if (value == '') {
                    return '请输入次卡发布数量！';
                }
            },

        });

        //普通图片上传    后台登录页背景图片
        var uploadInst2 = upload.render({
			elem: '#logoBtn2'
            ,url: '{:url("UpFiles/upload")}',
            accept:'images',
            acceptMime: 'image/*'
            ,size:0
            ,multiple:true
            ,number:1
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#SLogo2').attr('src',result); //图片链接（base64）
                });
            }
            ,done: function(res){
                    if(res.errorCode==8888){
                        $('#logo2').val(res.url);
                    }else{
						$('#SLogo2').attr('src','');
                        layer.msg(res.msg,{time:2000,icon:2});
                    }
                }
        });
        //提交监听
        form.on('submit(sys)', function (data) {
            $("#submit").attr({ disabled: "disabled" });
            loading = layer.load(1, { shade: [0.1, '#fff'] });
            let user = data.field
            let time = data.field.endtime

            if (time == null || !time) {
                data.field.endtime = 0
            }
            $.post("{:url('edit')}", data.field, function (res) {
                layer.close(loading);
                if (res.errorCode == 8888) {
                    layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                        location.href = res.url;
                    });
                } else {
                    $("#submit").removeAttr("disabled");
                    layer.msg(res.msg, { icon: 2, time: 1000 });
                }
            });
        })
    })


</script>


</body>

</html>